package com.xn.app.muying.util;

import java.util.LinkedList;
import java.util.List;
import android.app.Activity;
import android.app.Application;
/**
 * 退出程序，关闭所有Activity类
 * 
 * @author center
 *
 */
public class MyApplication extends Application {
	private List<Activity> activityList = new LinkedList<Activity>();
	private static MyApplication instance;

	private MyApplication() {
	}

	// 单例模式中获取唯一的MyApplication实例
	public static MyApplication getInstance() {
		if (null == instance) {
			instance = new MyApplication();
		}
		return instance;
	}

	// 添加Activity到容器中
	public void addActivity(Activity activity) {
		activityList.add(activity);
	}

	// 遍历所有Activity并finish
	public void exit() {
		if(activityList.size()>0){
		for (Activity activity : activityList) {
			activity.finish();
		}
		//退出当前运行的activity
		System.exit(0);
		}
	}
}
